#include <stdio.h>
#include <string.h>
#define BUFFER_SIZE 100

int compare (char *buffer, int len2)
{
    int len = len2;
    int var = 0;
    if((len % 2) == 0)
    {
        for(int idx = 0; idx < (len / 2); idx++)
        {
            if(buffer[idx] != buffer[len-idx-1])
            {
                //若不相等返回1
                var = 1;
                break;
            }
        }
    }
    else
    {
        int len1 = len-1;
        for(int idx = 0; idx < (len1 / 2); idx++)
        {
            if(buffer[idx] != buffer[len-idx-1])
            {
                //若不相等返回1
                var = 1;
                break;
            }
        }    
    }

    /* 到此一定是回文字符串 */
    return var;
}


int main()
{
#if 0
    char *buffer;//我就不想用BUFFER_SIZE
    printf("请输入一个字符串：");
    scanf("%s", buffer);//此处不用取地址，指针
    printf("%s\n",buffer);
#endif
    char buffer[BUFFER_SIZE];
    printf("请输入一个字符串：");
    scanf("%s", buffer);
    printf("buffer:%s\n",buffer);
    int len = strlen(buffer);
    printf("len:%d\n", len);
    int ret = compare(buffer, len);
    printf("%d\n", ret);
    if(ret != 0)
        printf("字符串buffer不是回文字符串\n");
    else
        printf("字符串buffer是回文字符串\n");

    return 0;

}




